﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Text.RegularExpressions;
using System.Windows.Forms;
using System.Globalization;

namespace BussinesLayer
{
    public class Validator
    {
        public static void ValidatorOnlyNumbers(object sender, KeyPressEventArgs e)
        {
            if (Char.IsNumber(e.KeyChar))
            {
                e.Handled = false;
            }
            else if (Char.IsControl(e.KeyChar))
            {
                e.Handled = false;
            }
            else
            {
                e.Handled = true;
            }
        }

        public static void ValidatorObjectEmpty(object sender, KeyPressEventArgs e)
        {
            if (Char.IsNumber(e.KeyChar))
            {
                e.Handled = true;
            }
            else if (Char.IsControl(e.KeyChar))
            {
                e.Handled = true;
            }
            else if (Char.IsLetterOrDigit(e.KeyChar))
            {
                e.Handled = true;
            }
            else
            {
                e.Handled = true;
            }
        }

        public static void ValidatorOnlyCharacters(object sender, KeyPressEventArgs e)
        {
            if (Char.IsLetter(e.KeyChar))
            {
                e.Handled = false;
            }
            else if (Char.IsControl(e.KeyChar))
            {
                e.Handled = false;
            }
            else if (Char.IsSeparator(e.KeyChar))
            {
                e.Handled = false;
            }
            else
            {
                e.Handled = true;
            }
        }

        public static void validacion_with_out_special_characters(object sender, KeyPressEventArgs e)
        {

            if (Char.IsLetter(e.KeyChar))
            {
                e.Handled = false;
            }
            else if (Char.IsControl(e.KeyChar))
            {
                e.Handled = false;
            }
            else if (Char.IsSeparator(e.KeyChar))
            {
                e.Handled = false;
            }
            else if (Char.IsDigit(e.KeyChar))
            {
                e.Handled = false;
            }
            else
            {
                e.Handled = true;
            }
        }

        public static bool IsValidEmailAddress(string sEmail)
        {
            if (sEmail == "")
            {
                return true;
            }
            else
            {
                return Regex.IsMatch(sEmail, @"^[-a-zA-Z0-9][-.a-zA-Z0-9]*@[-.a-zA-Z0-9]+(\.[-.a-zA-Z0-9]+)*\.(com|edu|info|gov|int|mil|net|org|biz|name|museum|coop|aero|pro|[a-zA-Z]{2})$", RegexOptions.IgnorePatternWhitespace);
            }
        }


        public static bool InvalidChars(string sInput)
        {

            string[] sBadChars = { "select", "drop", ";", "--", "insert", "delete", "xp_", "#", "%", "&", "'", "(", ")", "/", "\\", ":", ";", "<", ">", "=", "[", "]", "?", "`", "|" };
            string[] words = sInput.Split(' ');

            foreach (string bad in sBadChars)
            {
                foreach (string input in words)
                {
                    if (bad == input)
                    {
                        return true;
                    }
                }
            }
            return false;
        }

        public static string validateAddQuiekPatient(TextBox familyName_TextBox, TextBox givenName_TextBox)
        {
            string familyName = familyName_TextBox.Text;
            string givenName = givenName_TextBox.Text;
            if (familyName_TextBox.Text == "")
                return "-1";
            else
                if (familyName[0] == ' ')
                    return "-2";
                else
                    if (givenName_TextBox.Text == "")
                        return "-1";
                    else
                        if (givenName[0] == ' ')
                            return "-3";
                        else
                            return "1";
        }
    }
}
